import java.util.*;
public class Account implements Lockable
{
    private long stk;
    private String tentk;
    private double sotien;
    final double laisuat=0.02;
    int key;
    boolean _locked=false;
    
    
    public Account()
    {
        this.key=-1;
    }
    public Account(int _key,long sotk,String ten,double sotien1)
    {    
    	this.key=_key;
    	this.stk=sotk;
    	this.tentk=ten;
    	this.sotien=sotien1;      
    }
    public void nhapAccount()
    {           
        Scanner scan=new Scanner(System.in);
        System.out.println("Nhap so key cua tai khoan");
        key=scan.nextInt();
        System.out.println("Nhap so  tai khoan");
        stk=scan.nextLong();
        System.out.println("Nhap ten cua tai khoan");
        tentk=scan.next();
        System.out.println("Nhap so tien cua tai khoan");
        sotien=scan.nextDouble();           
    }
    public Account(long sotk,String ten)
    {
    	this.stk=sotk;
    	this.tentk=ten;
    	this.sotien=100;
    }
 
    public void setsotk(long sotk)
    {
        if(locked()==false)
        	this.stk=sotk;
            
    }
    public long getsotk()
    {           
        return this.stk;              
    } 
    public void settentk(String ten)
    {
        if(locked()==false)
                
        	this.tentk=ten;
    }
    public String gettentk()
    {           
        return this.tentk;
    }
    public void setsotien(double sotien1)
    {
    	this.sotien=sotien1;
    }
    public double getsotien() 
    {
        return this.sotien;
    }
    public void xuatAccount(String tiente)
    {
        if(locked()==false)
        {
	        System.out.println("So key tai khoan cua ban la "+key);
	        System.out.println("So tai khoan cua ban la "+this.stk);
	        System.out.println("Ten tai khoan cua ban la "+this.tentk);
	        System.out.println("So tien trong tai khoan cua ban la "+this.sotien+"VND");
        }
        else
        {
            System.out.println("Tai khoan dang bi khoa ");
        }
    }
    public void naptien(double sotiennap)
    {
        if(locked()==true) System.out.println("Xin loi tai khoan da khoa khong the tien hanh giao dich ");
        else    
        	this.sotien = sotien+sotiennap;
    }
    public void ruttien(double sotienrut,double phirut)
    {       
        if(locked()==true) 
        	System.out.println("Xin loi tai khoan da khoa khong the tien hanh giao dich ");
        else
        {       
	        if(sotien>sotienrut+phirut)
	        	this.sotien = sotien-(sotienrut+phirut);
        }
    }
    public void daohan()
    {
        if(locked()==false)                
        	this.sotien = sotien + (sotien*laisuat);
    }
    public void chuyenkhoan(Account y,double sotienchuyen,double phi)
    {
        if(locked()==true||y.locked()==true) 
        	System.out.println("Xin loi tai khoan da khoa khong the tien hanh giao dich do bi khoa ");
        else
        {
        	if(getsotien()>sotienchuyen+phi)
        	{       
		        ruttien(sotienchuyen,phi);
		        y.naptien(sotienchuyen);
        	}
        }
    }
    
    public void setKey(int _key) 
    {
        key=_key;
    }

    public void lock(int _keylock)
    {
        if(_keylock==key)
        {
            _locked=true;
        }
    }

    public void unlock(int _unkeylock) 
    {
        if(_unkeylock==key && _locked==true)
        {
            _locked=false;
        }
    }

    public boolean locked() 
    {
        if(_locked==true)
        return true;
        return false;
    }
    
    public static void main(String[] args)
    {
        int keylock=3;
        int n;
        Scanner scan1=new Scanner(System.in);
        System.out.println("Moi ban nhap so tai khoan can luu tru");
        n=scan1.nextInt();
        Account[] arr=new Account[n];
        for(int i=0;i<n;i++)
        {
            System.out.println("Moi ban nhap du lieu tai khoan "+(i+1));
            arr[i]=new Account();
            arr[i].nhapAccount();
        }
        System.out.println("Du lieu cac tai khoan vua nhap vao la ");
        for(int i=0;i<n;i++)
        {
            System.out.println("du lieu tai khoan "+(i+1));
            arr[i].xuatAccount("VND");
        }
        
        for(int i=0;i<n;i++)
        {
            arr[i].lock(keylock);
        }
   
        System.out.println("Tai khoan sau khi giao dich la");
        for(int i=0;i<n;i++)
        {
            arr[i].xuatAccount("VND");
        }
    }
    
}
